package com.myFwk.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @Title:
 * @Description:
 * @Author: guowl
 * @version： 1.0
 * @Date:2021/8/26
 * @Copyright: Copyright(c)2021 RedaFlight.com All Rights Reserved
 */
@RestController
public class UnserInfoController {

    /*
     * 此接口类似于授权服务器 每个获取用户的信息都要去请求改授权服务器的接口
     * */
    @GetMapping("/user/info")
    public Principal userInfo(Principal principal) {
        //此处的principal是由oAuthor2.0框架自动注入的
        //原理就是 利用Context概念，将授权用户放在线程里面，利用ThreadLocal来获取当前用户对象
        //也可以通过这正方式获取当前用户信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        Principal principal1 = (Principal)authentication.getPrincipal();
        return principal;
    }


}
